type BusClass = {
  emit: (name: string) => void;
  on: (name: string, callback: any) => void;
};
type pramsKey = string | number | symbol;

type List = {
  [key: pramsKey]: Array<any>;
};
class Bus implements BusClass {
  list: List
  constructor() {
    this.list = {}
  }

  emit(name: string, ...args: Array<any>) {
    const eventName: Array<any> = this.list[name]
    eventName?.forEach((fn) => {
      fn.apply(this, args)
    })
  }

  on(name: string, callback: any) {
    const fn: Array<any> = this.list[name] || []
    fn.push(callback)
    this.list[name] = fn
  }
}
export default new Bus()
